package net.qiqbframework.common;

import net.qiqbframework.config.ConfigurationException;
import net.qiqbframework.common.utils.StringUtils;

import java.util.Objects;
import java.util.function.Predicate;

public abstract class BuilderUtils {

    private BuilderUtils() {
        // Utility class
    }


    public static <T> void assertThat(T value,
                                      Predicate<T> assertion,
                                      String exceptionMessage) throws ConfigurationException {
        Assert.assertThat(value, assertion, () -> new ConfigurationException(exceptionMessage));
    }


    public static <T> void assertNonNull(T value, String exceptionMessage) throws ConfigurationException {
        assertThat(value, Objects::nonNull, exceptionMessage);
    }

    public static void assertPositive(int i, String exceptionMessage) {
        assertThat(i, number -> number >= 0, exceptionMessage);
    }


    public static void assertPositive(long l, String exceptionMessage) {
        assertThat(l, number -> number >= 0, exceptionMessage);
    }


    public static void assertStrictPositive(int i, String exceptionMessage) {
        assertThat(i, number -> number > 0, exceptionMessage);
    }


    public static void assertStrictPositive(long l, String exceptionMessage) {
        assertThat(l, number -> number > 0L, exceptionMessage);
    }


    public static void assertNonEmpty(String string, String exceptionMessage) {
        assertThat(string, StringUtils::nonEmptyOrNull, exceptionMessage);
    }


    public static void assertNonBlank(String string, String exceptionMessage) {
        assertThat(string, StringUtils::nonEmpty, exceptionMessage);
    }
}
